#ifndef     __PROGRESS_BAR_H
#define     __PROGRESS_BAR_H

#include <QPaintEvent>
#include <QWidget>
#include <QTimerEvent>

class ProgressBar : public QWidget {

public:
    ProgressBar(QWidget *parent = nullptr);

    enum Type {
        PROGRESS,
        ERR,
        SUCC,
        WARN,
    };

    void progress() {
        m_type = Type::PROGRESS;
        killTimer(m_timer_id);
        m_timer_id = startTimer(20);
        update();
    }

    void succ() {
        killTimer(m_timer_id);
        m_type = Type::SUCC;
        update();
    }

    void err() {
        killTimer(m_timer_id);
        m_type = Type::ERR;
        update();
    }

    void warn() {
        killTimer(m_timer_id);
        m_type = Type::WARN;
        update();
    }

protected:
    void paintEvent(QPaintEvent *event) override;
    void timerEvent(QTimerEvent *event) override;

private:
    Type m_type = Type::PROGRESS;
    int m_prog = 0;
    int m_timer_id = 0;
};


#endif
